<?php
class Pageley_Commerce_Command_ListMostRecentArticles extends Pageley_Controller_Command_TransactionalRead {

    private $limitAmount;

    public function setLimitAmount($limitAmount) {
        $this->limitAmount = $limitAmount;
    }

    protected function executeInternal() {
        $unitOfWork = $this->getUnitOfWork();
        $query = new Pageley_Query_Basic(
            Pageley_Commerce_Domain_Article::type(), null,
            new Pageley_Util_ArrayMap(array(
                "date" => Pageley_Query_Direction::$DESCENDING
            )),
            new Pageley_Query_Range(1, $this->limitAmount));
        $model = new Pageley_Util_ArrayMap();
        $articles = $unitOfWork->query($query);
        $model->put(Pageley_Commerce_Request::ARTICLES, $articles);
        return new Pageley_Controller_ModelAndView($model);
    }
}